package com.origin.oss.specification;

import com.origin.oss.enums.StorageType;
import com.origin.oss.specification.domain.multipart.response.QuickUploadResp;
import com.origin.oss.specification.domain.multipart.request.SliceUploadReq;
import com.origin.oss.specification.domain.multipart.response.CompleteSliceUploadResp;
import com.origin.oss.specification.domain.multipart.response.SliceUploadResp;
import com.origin.oss.specification.domain.object.UploadObjectDomain;

import java.io.InputStream;
import java.util.Collections;
import java.util.List;

/**
 * @author yezh
 * @date 2024/2/21 16:34
 */
public interface IOssClient {

    StorageType getStorageType();


    // ============================================= 文件上传 ============================================================

    default UploadObjectDomain uploadFile(String fileKey, InputStream is) {
        return uploadFile(fileKey, is, true);
    }

    UploadObjectDomain uploadFile(String fileKey, InputStream is, boolean isOverride);

    /**
     * 快速上传
     *
     * @param identifier 文件 md5
     */
    QuickUploadResp quickUpload(String identifier);

    /**
     * 分片上传
     */
    SliceUploadResp sliceUpload(SliceUploadReq sliceUploadReq);

    /**
     * 判断分片是否上传完成
     */
    boolean checkSliceUploadComplete(SliceUploadReq sliceUploadReq);

    /**
     * 获取已上传的分片
     *
     * @param identifier 文件 md5
     * @return 已上传的分片序号
     */
    default List<Integer> getUploadedSlice(String identifier) {
        return Collections.emptyList();
    }

    /**
     * 完成分片上传
     */
    CompleteSliceUploadResp completeSliceUpload(SliceUploadReq sliceUploadReq);

    /**
     * 中止分片上传
     */
    void abortSliceUpload(SliceUploadReq sliceUploadReq);

}
